package Offline;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class Offline {
    /**
     *
     */
    private static final long serialVersionUID = 2866162298888871585L;/*这个id没什么用*/
    /**
     * 从这往下是GUI添加组件的代码部分，可以不看
     */
    private JButton jButton2;        /*jButton1是START ,jButton2是RESET*/
    private JButton jButton1;
    private JToggleButton NumB14;		/*这是24个微动开关，也就是以他们输入的01序列来决定运算方法，按下表示输入是1，不按表示输入是0*/
    private JToggleButton NumB5;
    private JToggleButton NumB6;
    private JToggleButton NumB7;
    private JToggleButton NumB8;
    private JToggleButton NumB9;
    private JToggleButton NumB10;
    private JToggleButton NumB11;
    private JToggleButton NumB12;
    private JToggleButton NumB2;
    private JToggleButton NumB1;
    private JToggleButton NumB13;
    private JToggleButton NumB15;
    private JToggleButton NumB4;
    private JToggleButton NumB16;
    private JToggleButton NumB17;
    private JToggleButton NumB18;
    private JToggleButton NumB19;
    private JToggleButton NumB20;
    private JToggleButton NumB21;
    private JToggleButton NumB22;
    private JToggleButton NumB23;
    private JToggleButton NumB24;
    private JToggleButton NumB3;
    private JTextField jTextField8;		/*这是一些面板上的标签和输入框*/
    private JTextField jTextField7;
    private JTextField jTextField6;
    private JTextField jTextField5;
    private JTextField jTextField4;
    private JTextField jTextField3;
    private JTextField jTextField2;
    private JTextField jTextField1;
    private JTextField R11_d;		/*文本框Rx_d表示寄存器的名字标签，文本框Rx显示相应寄存器的值*/
    private JTextField R10_d;
    private JTextField R9_d;
    private JTextField R8_d;
    private JTextField R7_d;
    private JTextField R6_d;
    private JTextField R11;
    private JTextField R10;
    private JTextField R9;
    private JTextField R8;
    private JTextField R7;
    private JTextField R6;
    private JTextField R5_d;
    private JTextField R4_d;
    private JTextField R3_d;
    private JTextField R2_d;
    private JTextField R1_d;
    private JTextField R0_d;
    private JTextField R5;
    private JTextField R4;
    private JTextField R3;
    private JTextField R2;
    private JTextField R1;
    private JTextField R0;
    private JTextField ALU;		/*也是一些文本框*/
    private JTextField Text2;
    private JTextField CZVS;
    private JTextField Text1;
    private JTextField Data;
    private JTextField Text;
    /**
     * 以上是GUI用到的组件
     */
    public static char FunctionNum1[] = new char[12];	/*前12个微动开关的输入保存在这里*/
    public static char FunctionNum2[] = new char[12];	/*后12个微动开关的输入保存在这里*/
    public static String R[] = new String[12];		/*十二个寄存器的值暂时保存在这里*/
    public static String FQ[] = new String[2];		/*运算中用到的F寄存器和Q寄存器*/
    public char cCZVS[] = new char[4];		/*CZVS寄存器。。其实没有用到*/
    int Cin;		/*进位标志位，也就是C寄存器*/
    /**
     * Auto-generated main method to display this JFrame
     */

    public JPanel getOffline(){
        return initGui();
    }

    private JPanel initGui(){

        JPanel jPanel = new JPanel();

        for(int i = 0;i < 12;i++)	/*在初始化GUI的同时为数组初始化*/
        {
            FunctionNum1[i] = '0';
            FunctionNum2[i] = '0';
        }

        try {
            {
                jPanel.setSize(647, 393);
            }
            jPanel.setLayout(null);
//            jPanel.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
            jPanel.setBackground(new java.awt.Color(245,245,245));

            {
                NumB24 = new JToggleButton();
                jPanel.add(NumB24);
                NumB24.setText("12");
                NumB24.setBackground(new Color(255,255,255));
                NumB24.setMargin(new java.awt.Insets(0,0,0,0));
                NumB24.setBounds(639, 400, 40, 40);
                NumB24.setFont(new java.awt.Font("微软雅黑",1,20));
                NumB24.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        NumB24ActionPerformed(evt);
                    }
                });
            }
            {
                NumB23 = new JToggleButton();
                jPanel.add(NumB23);
                NumB23.setText("11");
                NumB23.setBackground(new Color(255,255,255));
                NumB23.setMargin(new java.awt.Insets(0,0,0,0));
                NumB23.setBounds(599, 400, 40, 40);
                NumB23.setFont(new java.awt.Font("微软雅黑",1,20));
                NumB23.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        NumB23ActionPerformed(evt);
                    }
                });
            }
            {
                NumB22 = new JToggleButton();
                jPanel.add(NumB22);
                NumB22.setText("10");
                NumB22.setBackground(new Color(255,255,255));
                NumB22.setMargin(new java.awt.Insets(0,0,0,0));
                NumB22.setBounds(559, 400, 40, 40);
                NumB22.setFont(new java.awt.Font("微软雅黑",1,20));
                NumB22.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        NumB22ActionPerformed(evt);
                    }
                });
            }
            {
                NumB21 = new JToggleButton();
                jPanel.add(NumB21);
                NumB21.setText("9");
                NumB21.setBackground(new Color(255,255,255));
                NumB21.setMargin(new java.awt.Insets(0,0,0,0));
                NumB21.setBounds(519, 400, 40, 40);
                NumB21.setFont(new java.awt.Font("微软雅黑",1,20));
                NumB21.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        NumB21ActionPerformed(evt);
                    }
                });
            }
            {
                NumB20 = new JToggleButton();
                jPanel.add(NumB20);
                NumB20.setText("8");
                NumB20.setBackground(new Color(255,255,255));
                NumB20.setMargin(new java.awt.Insets(0,0,0,0));
                NumB20.setBounds(480, 400, 40, 40);
                NumB20.setFont(new java.awt.Font("微软雅黑",1,20));
                NumB20.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        NumB20ActionPerformed(evt);
                    }
                });
            }
            {
                NumB19 = new JToggleButton();
                jPanel.add(NumB19);
                NumB19.setText("7");
                NumB19.setBackground(new Color(255,255,255));
                NumB19.setMargin(new java.awt.Insets(0,0,0,0));
                NumB19.setBounds(440, 400, 40, 40);
                NumB19.setFont(new java.awt.Font("微软雅黑",1,20));
                NumB19.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        NumB19ActionPerformed(evt);
                    }
                });
            }
            {
                NumB18 = new JToggleButton();
                jPanel.add(NumB18);
                NumB18.setText("6");
                NumB18.setBackground(new Color(255,255,255));
                NumB18.setMargin(new java.awt.Insets(0,0,0,0));
                NumB18.setBounds(400, 400, 40, 40);
                NumB18.setFont(new java.awt.Font("微软雅黑",1,20));
                NumB18.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        NumB18ActionPerformed(evt);
                    }
                });
            }
            {
                NumB17 = new JToggleButton();
                jPanel.add(NumB17);
                NumB17.setText("5");
                NumB17.setBackground(new Color(255,255,255));
                NumB17.setMargin(new java.awt.Insets(0,0,0,0));
                NumB17.setBounds(360, 400, 40, 40);
                NumB17.setFont(new java.awt.Font("微软雅黑",1,20));
                NumB17.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        NumB17ActionPerformed(evt);
                    }
                });
            }
            {
                NumB16 = new JToggleButton();
                jPanel.add(NumB16);
                NumB16.setText("4");
                NumB16.setBackground(new Color(255,255,255));
                NumB16.setMargin(new java.awt.Insets(0,0,0,0));
                NumB16.setBounds(320, 400, 40, 40);
                NumB16.setFont(new java.awt.Font("微软雅黑",1,20));
                NumB16.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        NumB16ActionPerformed(evt);
                    }
                });
            }

            {
                NumB15 = new JToggleButton();
                jPanel.add(NumB15);
                NumB15.setText("3");
                NumB15.setBackground(new Color(255,255,255));
                NumB15.setMargin(new java.awt.Insets(0,0,0,0));
                NumB15.setBounds(280, 400, 40, 40);
                NumB15.setFont(new java.awt.Font("微软雅黑",1,20));
                NumB15.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        NumB15ActionPerformed(evt);
                    }
                });
            }
            {
                NumB14 = new JToggleButton();
                jPanel.add(NumB14);
                NumB14.setText("2");
                NumB14.setBackground(new Color(255,255,255));
                NumB14.setMargin(new java.awt.Insets(0,0,0,0));
                NumB14.setBounds(240, 400, 40, 40);
                NumB14.setFont(new java.awt.Font("微软雅黑",1,20));
                NumB14.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        NumB14ActionPerformed(evt);
                    }
                });
            }
            {
                NumB13 = new JToggleButton();
                jPanel.add(NumB13);
                NumB13.setText("1");
                NumB13.setBackground(new Color(255,255,255));
                NumB13.setMargin(new java.awt.Insets(0,0,0,0));
                NumB13.setBounds(200, 400, 50, 50);
                NumB13.setSize(40, 40);
                NumB13.setFont(new java.awt.Font("微软雅黑",1,20));
                NumB13.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        NumB13ActionPerformed(evt);
                    }
                });
            }

            {
                NumB12 = new JToggleButton();
                jPanel.add(NumB12);
                NumB12.setText("12");
                NumB12.setBackground(new Color(255,255,255));
                NumB12.setMargin(new java.awt.Insets(0,0,0,0));
                NumB12.setBounds(639, 299, 40, 40);
                NumB12.setFont(new java.awt.Font("微软雅黑",1,20));
                NumB12.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        NumB12ActionPerformed(evt);
                    }
                });
            }
            {
                NumB11 = new JToggleButton();
                jPanel.add(NumB11);
                NumB11.setText("11");
                NumB11.setBackground(new Color(255,255,255));
                NumB11.setMargin(new java.awt.Insets(0,0,0,0));
                NumB11.setBounds(599, 299, 40, 40);
                NumB11.setFont(new java.awt.Font("微软雅黑",1,20));
                NumB11.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        NumB11ActionPerformed(evt);
                    }
                });
            }
            {
                NumB10 = new JToggleButton();
                jPanel.add(NumB10);
                NumB10.setText("10");
                NumB10.setBackground(new Color(255,255,255));
                NumB10.setMargin(new java.awt.Insets(0,0,0,0));
                NumB10.setBounds(559, 299, 40, 40);
                NumB10.setFont(new java.awt.Font("微软雅黑",1,20));
                NumB10.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        NumB10ActionPerformed(evt);
                    }
                });
            }
            {
                NumB9 = new JToggleButton();
                jPanel.add(NumB9);
                NumB9.setText("9");
                NumB9.setBackground(new Color(255,255,255));
                NumB9.setMargin(new java.awt.Insets(0,0,0,0));
                NumB9.setBounds(520, 299, 40, 40);
                NumB9.setFont(new java.awt.Font("微软雅黑",1,20));
                NumB9.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        NumB9ActionPerformed(evt);
                    }
                });
            }
            {
                NumB8 = new JToggleButton();
                jPanel.add(NumB8);
                NumB8.setText("8");
                NumB8.setBackground(new Color(255,255,255));
                NumB8.setMargin(new java.awt.Insets(0,0,0,0));
                NumB8.setBounds(480, 299, 40, 40);
                NumB8.setFont(new java.awt.Font("微软雅黑",1,20));
                NumB8.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        NumB8ActionPerformed(evt);
                    }
                });
            }
            {
                NumB7 = new JToggleButton();
                jPanel.add(NumB7);
                NumB7.setText("7");
                NumB7.setBackground(new Color(255,255,255));
                NumB7.setMargin(new java.awt.Insets(0,0,0,0));
                NumB7.setBounds(440, 299, 40, 40);
                NumB7.setFont(new java.awt.Font("微软雅黑",1,20));
                NumB7.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        NumB7ActionPerformed(evt);
                    }
                });
            }
            {
                NumB6 = new JToggleButton();
                jPanel.add(NumB6);
                NumB6.setText("6");
                NumB6.setBackground(new Color(255,255,255));
                NumB6.setMargin(new java.awt.Insets(0,0,0,0));
                NumB6.setBounds(400, 299, 40, 40);
                NumB6.setFont(new java.awt.Font("微软雅黑",1,20));
                NumB6.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        NumB6ActionPerformed(evt);
                    }
                });
            }
            {
                NumB5 = new JToggleButton();
                jPanel.add(NumB5);
                NumB5.setText("5");
                NumB5.setBackground(new Color(255,255,255));
                NumB5.setMargin(new java.awt.Insets(0,0,0,0));
                NumB5.setBounds(360, 299, 40, 40);
                NumB5.setFont(new java.awt.Font("微软雅黑",1,20));
                NumB5.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        NumB5ActionPerformed(evt);
                    }
                });
            }
            {
                NumB4 = new JToggleButton();
                jPanel.add(NumB4);
                NumB4.setText("4");
                NumB4.setBackground(new Color(255,255,255));
                NumB4.setMargin(new java.awt.Insets(0,0,0,0));
                NumB4.setBounds(320, 299, 40, 40);
                NumB4.setFont(new java.awt.Font("微软雅黑",1,20));
                NumB4.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        NumB4ActionPerformed(evt);
                    }
                });
            }
            {
                NumB3 = new JToggleButton();
                jPanel.add(NumB3);
                NumB3.setText("3");
                NumB3.setBackground(new Color(255,255,255));
                NumB3.setBounds(281, 299, 40, 40);
                NumB3.setMargin(new java.awt.Insets(0, 0, 0, 0));
                NumB3.setFont(new java.awt.Font("微软雅黑",1,20));
                NumB3.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        NumB3ActionPerformed(evt);
                    }
                });
            }

            {
                NumB2 = new JToggleButton();
                jPanel.add(NumB2);
                NumB2.setText("2");
                NumB2.setBackground(new Color(255,255,255));
                NumB2.setMargin(new java.awt.Insets(0,0,0,0));
                NumB2.setBounds(240, 299, 40, 40);
                NumB2.setFont(new java.awt.Font("微软雅黑",1,20));
                NumB2.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent evt) {
                        NumB2ActionPerformed(evt);
                    }
                });
            }
            {
                jButton1 = new JButton();
                jPanel.add(jButton1);
                jButton1.setText("START");
                jButton1.setBackground(new Color(255,255,255));
                jButton1.setBounds(48, 299, 100, 40);
                jButton1.setMargin(new java.awt.Insets(0, 0, 0, 0));
                jButton1.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        jButton1ActionPerformed(evt);
                    }
                });
            }
            {
                NumB1 = new JToggleButton();
                jPanel.add(NumB1);
                NumB1.setText("1");
                NumB1.setBackground(new Color(255,255,255));
                NumB1.setMargin(new java.awt.Insets(0,0,0,0));
                NumB1.setBounds(200, 299, 25, 25);
                NumB1.setSize(40, 40);
                NumB1.setFont(new java.awt.Font("微软雅黑",1,20));
                NumB1.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        NumB1ActionPerformed(evt);
                    }
                });
            }
            {
                jButton2 = new JButton();
                jPanel.add(jButton2);
                jButton2.setText("RESET");
                jButton2.setBackground(new Color(255,255,255));
                jButton2.setBounds(48, 400, 50, 25);
                jButton2.setMargin(new java.awt.Insets(0, 0, 0, 0));
                jButton2.setSize(100, 40);
                jButton2.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        jButton2ActionPerformed(evt);
                    }
                });
            }
            {
                Text = new JTextField();
                jPanel.add(Text);
                Text.setText("Data");
                Text.setHorizontalAlignment(JTextField.CENTER);
                Text.setBounds(48, 160, 50, 30);
                Text.setEditable(false);
            }
            {
                Data = new JTextField();
                jPanel.add(Data);
                Data.setText("\u8f93\u5165\u56db\u4f4d\u5341\u516d\u8fdb\u5236\u6570");

                Data.setBounds(120, 160, 150, 30);
                Data.addMouseListener(new MouseAdapter() {
                    public void mouseEntered(MouseEvent evt) {
                        System.out.println("Data.mouseEntered, event="+evt);
                        //TODO add your code for Data.mouseEntered
                    }
                    public void mouseClicked(MouseEvent evt) {
                        DataMouseClicked(evt);
                    }
                });
            }
            {
                Text1 = new JTextField();
                jPanel.add(Text1);
                Text1.setText("CZVS");
                Text1.setHorizontalAlignment(JTextField.CENTER);
                Text1.setBounds(48, 48, 50, 30);
                Text1.setEditable(false);
            }
            {
                CZVS = new JTextField();
                jPanel.add(CZVS);
                CZVS.setBounds(120, 48, 150, 30);
                CZVS.setEditable(false);
                CZVS.setSelectionColor(new java.awt.Color(255,255,255));
            }
            {
                Text2 = new JTextField();
                jPanel.add(Text2);
                Text2.setText("A L U");
                Text2.setHorizontalAlignment(JTextField.CENTER);
                Text2.setBounds(48, 104, 50, 30);
                Text2.setEditable(false);
            }
            {
                ALU = new JTextField();
                jPanel.add(ALU);
                ALU.setBounds(120, 104, 150, 30);
                ALU.setSelectionColor(new java.awt.Color(255,255,255));
                ALU.setEditable(false);
                ALU.addMouseListener(new MouseAdapter() {
                    public void mouseClicked(MouseEvent evt) {
                        ALUMouseClicked(evt);
                    }
                });
            }
            {
                R0 = new JTextField();
                jPanel.add(R0);
                R0.setText("R0:");
                R0.setBounds(358, 48, 24, 24);
                R0.setEditable(false);
            }
            {
                R1 = new JTextField();
                jPanel.add(R1);
                R1.setText("R1:");
                R1.setBounds(358, 72, 24, 24);
                R1.setEditable(false);
            }
            {
                R2 = new JTextField();
                jPanel.add(R2);
                R2.setText("R2:");
                R2.setBounds(358, 96, 24, 24);
                R2.setEditable(false);
            }
            {
                R3 = new JTextField();
                jPanel.add(R3);
                R3.setText("R3:");
                R3.setBounds(358, 120, 24, 24);
                R3.setEditable(false);
            }
            {
                R4 = new JTextField();
                jPanel.add(R4);
                R4.setText("R4:");
                R4.setBounds(358, 144, 24, 24);
                R4.setEditable(false);
            }
            {
                R5 = new JTextField();
                jPanel.add(R5);
                R5.setText("R5:");
                R5.setBounds(358, 168, 24, 24);
                R5.setEditable(false);
            }
            {
                R0_d = new JTextField();
                jPanel.add(R0_d);
                R0_d.setBounds(382, 48, 68, 24);
            }
            {
                R1_d = new JTextField();
                jPanel.add(R1_d);
                R1_d.setBounds(382, 72, 68, 24);
            }
            {
                R2_d = new JTextField();
                jPanel.add(R2_d);
                R2_d.setBounds(382, 96, 68, 24);
            }
            {
                R3_d = new JTextField();
                jPanel.add(R3_d);
                R3_d.setBounds(382, 120, 68, 24);
            }
            {
                R4_d = new JTextField();
                jPanel.add(R4_d);
                R4_d.setBounds(382, 144, 68, 24);
            }
            {
                R5_d = new JTextField();
                jPanel.add(R5_d);
                R5_d.setBounds(382, 168, 68, 24);
            }
            {
                R6 = new JTextField();
                jPanel.add(R6);
                R6.setText("R6:");
                R6.setBounds(525, 48, 24, 24);
                R6.setEditable(false);
            }
            {
                R7 = new JTextField();
                jPanel.add(R7);
                R7.setText("R7:");
                R7.setBounds(525, 72, 24, 24);
                R7.setEditable(false);
            }
            {
                R8 = new JTextField();
                jPanel.add(R8);
                R8.setText("R8:");
                R8.setBounds(525, 96, 24, 24);
                R8.setEditable(false);
            }
            {
                R9 = new JTextField();
                jPanel.add(R9);
                R9.setText("R9:");
                R9.setBounds(525, 120, 24, 24);
                R9.setEditable(false);
            }
            {
                R10 = new JTextField();
                jPanel.add(R10);
                R10.setText("R10:");
                R10.setBounds(525, 144, 24, 24);
                R10.setFont(new java.awt.Font("微软雅黑",0,9));
                R10.setEditable(false);
            }
            {
                R11 = new JTextField();
                jPanel.add(R11);
                R11.setText("R11:");
                R11.setBounds(525, 168, 24, 24);
                R11.setFont(new java.awt.Font("微软雅黑",0,9));
                R11.setEditable(false);
            }
            {
                R6_d = new JTextField();
                jPanel.add(R6_d);
                R6_d.setBounds(549, 48, 68, 24);
            }
            {
                R7_d = new JTextField();
                jPanel.add(R7_d);
                R7_d.setBounds(549, 72, 68, 24);
            }
            {
                R8_d = new JTextField();
                jPanel.add(R8_d);
                R8_d.setBounds(549, 96, 68, 24);
            }
            {
                R9_d = new JTextField();
                jPanel.add(R9_d);
                R9_d.setBounds(549, 120, 68, 24);
            }
            {
                R10_d = new JTextField();
                jPanel.add(R10_d);
                R10_d.setBounds(549, 144, 68, 24);
            }
            {
                R11_d = new JTextField();
                jPanel.add(R11_d);
                R11_d.setBounds(549, 167, 68, 24);
            }
            {
                jTextField1 = new JTextField();
                jPanel.add(jTextField1);
                jTextField1.setText("I8-I6:");
                jTextField1.setBounds(200, 274, 40, 25);
                jTextField1.setFont(new java.awt.Font("微软雅黑",0,16));
                jTextField1.setEditable(false);
            }
            {
                jTextField2 = new JTextField();
                jPanel.add(jTextField2);
                jTextField2.setFont(new java.awt.Font("微软雅黑",0,16));
                jTextField2.setText("I5-I3:");
                jTextField2.setEditable(false);
                jTextField2.setBounds(321, 274, 40, 25);
            }
            {
                jTextField3 = new JTextField();
                jPanel.add(jTextField3);
                jTextField3.setFont(new java.awt.Font("微软雅黑",0,16));
                jTextField3.setText("I2-I0:");
                jTextField3.setEditable(false);
                jTextField3.setBounds(440, 274, 40, 25);
            }
            {
                jTextField4 = new JTextField();
                jPanel.add(jTextField4);
                jTextField4.setFont(new java.awt.Font("微软雅黑",0,16));
                jTextField4.setText("SST:");
                jTextField4.setEditable(false);
                jTextField4.setBounds(560, 274, 40, 25);
            }
            {
                jTextField5 = new JTextField();
                jPanel.add(jTextField5);
                jTextField5.setFont(new java.awt.Font("微软雅黑",0,16));
                jTextField5.setText("SSH:");
                jTextField5.setEditable(false);
                jTextField5.setBounds(200, 375, 40, 25);
            }
            {
                jTextField6 = new JTextField();
                jPanel.add(jTextField6);
                jTextField6.setFont(new java.awt.Font("微软雅黑",0,16));
                jTextField6.setText("SCI:");
                jTextField6.setEditable(false);
                jTextField6.setBounds(280, 375, 40, 25);
            }
            {
                jTextField7 = new JTextField();
                jPanel.add(jTextField7);
                jTextField7.setFont(new java.awt.Font("微软雅黑",0,16));
                jTextField7.setText("B PORT:");
                jTextField7.setEditable(false);
                jTextField7.setBounds(360, 375, 80, 25);
            }
            {
                jTextField8 = new JTextField();
                jPanel.add(jTextField8);
                jTextField8.setFont(new java.awt.Font("微软雅黑",0,16));
                jTextField8.setText("A PORT:");
                jTextField8.setEditable(false);
                jTextField8.setBounds(520, 375, 80, 25);
            }
//            jPanel.pack();
            jPanel.setSize(728, 503);
        } catch (Exception e) {
            //add your error handling code here
            e.printStackTrace();
        }

        return jPanel;
    }


    private void NumB1ActionPerformed(ActionEvent evt) {
        //TODO add your code for NumB1.actionPerformed
        AbstractButton but = (AbstractButton)evt.getSource();
        boolean selected = but.getModel().isSelected();
        if(selected)
            FunctionNum1[0] = '1';
        else
            FunctionNum1[0] = '0';
    }

    private void NumB3ActionPerformed(ActionEvent evt) {
        AbstractButton but = (AbstractButton)evt.getSource();
        boolean selected = but.getModel().isSelected();
        if(selected)
            FunctionNum1[2] = '1';
        else
            FunctionNum1[2] = '0';
    }

    private void NumB2ActionPerformed(ActionEvent evt) {
        AbstractButton but = (AbstractButton)evt.getSource();
        boolean selected = but.getModel().isSelected();
        if(selected)
            FunctionNum1[1] = '1';
        else
            FunctionNum1[1] = '0';
    }

    private void NumB4ActionPerformed(ActionEvent evt) {
        AbstractButton but = (AbstractButton)evt.getSource();
        boolean selected = but.getModel().isSelected();
        if(selected)
            FunctionNum1[3] = '1';
        else
            FunctionNum1[3] = '0';
    }

    private void NumB5ActionPerformed(ActionEvent evt) {
        AbstractButton but = (AbstractButton)evt.getSource();
        boolean selected = but.getModel().isSelected();
        if(selected)
            FunctionNum1[4] = '1';
        else
            FunctionNum1[4] = '0';
    }

    private void NumB6ActionPerformed(ActionEvent evt) {
        AbstractButton but = (AbstractButton)evt.getSource();
        boolean selected = but.getModel().isSelected();
        if(selected)
            FunctionNum1[5] = '1';
        else
            FunctionNum1[5] = '0';
    }

    private void NumB7ActionPerformed(ActionEvent evt) {
        AbstractButton but = (AbstractButton)evt.getSource();
        boolean selected = but.getModel().isSelected();
        if(selected)
            FunctionNum1[6] = '1';
        else
            FunctionNum1[6] = '0';
    }

    private void NumB8ActionPerformed(ActionEvent evt) {
        AbstractButton but = (AbstractButton)evt.getSource();
        boolean selected = but.getModel().isSelected();
        if(selected)
            FunctionNum1[7] = '1';
        else
            FunctionNum1[7] = '0';
    }

    private void NumB9ActionPerformed(ActionEvent evt) {
        AbstractButton but = (AbstractButton)evt.getSource();
        boolean selected = but.getModel().isSelected();
        if(selected)
            FunctionNum1[8] = '1';
        else
            FunctionNum1[8] = '0';
    }

    private void NumB10ActionPerformed(ActionEvent evt) {
        AbstractButton but = (AbstractButton)evt.getSource();
        boolean selected = but.getModel().isSelected();
        if(selected)
            FunctionNum1[9] = '1';
        else
            FunctionNum1[9] = '0';
    }

    private void NumB11ActionPerformed(ActionEvent evt) {
        AbstractButton but = (AbstractButton)evt.getSource();
        boolean selected = but.getModel().isSelected();
        if(selected)
            FunctionNum1[10] = '1';
        else
            FunctionNum1[10] = '0';
    }

    private void NumB12ActionPerformed(ActionEvent evt) {
        AbstractButton but = (AbstractButton)evt.getSource();
        boolean selected = but.getModel().isSelected();
        if(selected)
            FunctionNum1[11] = '1';
        else
            FunctionNum1[11] = '0';
    }

    private void NumB13ActionPerformed(ActionEvent evt) {
        AbstractButton but = (AbstractButton)evt.getSource();
        boolean selected = but.getModel().isSelected();
        if(selected)
            FunctionNum2[0] = '1';
        else
            FunctionNum2[0] = '0';
    }

    private void NumB14ActionPerformed(ActionEvent evt) {
        AbstractButton but = (AbstractButton)evt.getSource();
        boolean selected = but.getModel().isSelected();
        if(selected)
            FunctionNum2[1] = '1';
        else
            FunctionNum2[1] = '0';
    }

    private void NumB15ActionPerformed(ActionEvent evt) {
        AbstractButton but = (AbstractButton)evt.getSource();
        boolean selected = but.getModel().isSelected();
        if(selected)
            FunctionNum2[2] = '1';
        else
            FunctionNum2[2] = '0';
    }

    private void NumB16ActionPerformed(ActionEvent evt) {
        AbstractButton but = (AbstractButton)evt.getSource();
        boolean selected = but.getModel().isSelected();
        if(selected)
            FunctionNum2[3] = '1';
        else
            FunctionNum2[3] = '0';
    }

    private void NumB17ActionPerformed(ActionEvent evt) {
        AbstractButton but = (AbstractButton)evt.getSource();
        boolean selected = but.getModel().isSelected();
        if(selected)
            FunctionNum2[4] = '1';
        else
            FunctionNum2[4] = '0';
    }

    private void NumB18ActionPerformed(ActionEvent evt) {
        AbstractButton but = (AbstractButton)evt.getSource();
        boolean selected = but.getModel().isSelected();
        if(selected)
            FunctionNum2[5] = '1';
        else
            FunctionNum2[5] = '0';
    }

    private void NumB19ActionPerformed(ActionEvent evt) {
        AbstractButton but = (AbstractButton)evt.getSource();
        boolean selected = but.getModel().isSelected();
        if(selected)
            FunctionNum2[6] = '1';
        else
            FunctionNum2[6] = '0';
    }

    private void NumB20ActionPerformed(ActionEvent evt) {
        AbstractButton but = (AbstractButton)evt.getSource();
        boolean selected = but.getModel().isSelected();
        if(selected)
            FunctionNum2[7] = '1';
        else
            FunctionNum2[7] = '0';
    }

    private void NumB21ActionPerformed(ActionEvent evt) {
        AbstractButton but = (AbstractButton)evt.getSource();
        boolean selected = but.getModel().isSelected();
        if(selected)
            FunctionNum2[8] = '1';
        else
            FunctionNum2[8] = '0';
    }

    private void NumB22ActionPerformed(ActionEvent evt) {
        AbstractButton but = (AbstractButton)evt.getSource();
        boolean selected = but.getModel().isSelected();
        if(selected)
            FunctionNum2[9] = '1';
        else
            FunctionNum2[9] = '0';
    }

    private void NumB23ActionPerformed(ActionEvent evt) {
        AbstractButton but = (AbstractButton)evt.getSource();
        boolean selected = but.getModel().isSelected();
        if(selected)
            FunctionNum2[10] = '1';
        else
            FunctionNum2[10] = '0';
    }

    private void NumB24ActionPerformed(ActionEvent evt) {
        AbstractButton but = (AbstractButton)evt.getSource();
        boolean selected = but.getModel().isSelected();
        if(selected)
            FunctionNum2[11] = '1';
        else
            FunctionNum2[11] = '0';
    }
    /**
     * 在web端重做应该只用到下面的五个函数
     * START键的响应函数
     * @param evt
     */
    private void jButton1ActionPerformed(ActionEvent evt) {
        String inFunction1 = new String(FunctionNum1);	/*第一排微动开关的输入，包括I0-I8和SST*/
        String inFunction2 = new String(FunctionNum2);	/*第二排微动开关的输入，包括SSHSCI和PortA、PortB*/
        /*从输入中提取响应的控制位*/
        String I8_6 = inFunction1.substring(0,3);	/*I8-I6表示输出哪个寄存器的值*/
        String I5_3 = inFunction1.substring(3,6);	/*I5-I3表示采取哪种运算*/
        String I2_0 = inFunction1.substring(6,9);	/*I2-I0表示数据来源*/
        String SST = inFunction1.substring(9,12);	/*SST决定CZVS寄存器的值，本次试验中衡为001*/
        String SSHSCI = inFunction2.substring(1,4);	/*SSHSCI在减法时应为001，其他未考虑*/
        String bPort = inFunction2.substring(4,8);	/*操作数B的寄存器编号*/
        String aPort = inFunction2.substring(8,12);	/*操作数A的寄存器编号*/

        //以下按运算逻辑进行数据处理
        if(SSHSCI.equals("000"))
            Cin = 0;
        else if(SSHSCI.equals("001"))
            Cin = 1;
        else
            Cin = (int)cCZVS[0];
        int B = Integer.parseInt(bPort,2);	/*获取A操作数地址*/
        int A = Integer.parseInt(aPort,2);	/*获取B操作数地址*/
        String s_S = getS(I2_0,FQ,A,B);	/*调用getS()函数根据数据源、AB操作数地址和FQ寄存器的值获取目的操作数*/
        String s_R = getR(I2_0,A);	/*调用getR()函数根据数据源和A操作数的地址获取源操作数*/
        String ans = Do(I5_3,SST,SSHSCI,s_R,s_S,cCZVS);	/*调用Do()函数进行I5-I3指定的运算，对s_R,s_S表示的操作数进行操作，结果保存在ans中*/
        /*对ans进行处理，保证其长度为四位*/
        if(ans.length() > 4)
        {
            String ANS = "";
            for(int l = ans.length() - 1;l > ans.length() - 5;l--)
                ANS = ans.charAt(l) + ANS;
            ans = ANS;
        }
        for(int j = ans.length();j < 4;j++)
            ans = '0' + ans;
        FQ[0] = ans;//将运算结果保存到F寄存器
        System.out.println(ans);//测试用
        int i = Integer.parseInt(I8_6,2);
        switch(i)//根据I8-I6的值决定输出哪个寄存器的值，并对FQ寄存器中的值进行处理
        {
            case 0:
            {
                FQ[1] = FQ[0];
                ALU.setText(FQ[0]);
            }break;
            case 1:
            {
                ALU.setText(FQ[0]);
            }break;
            case 2:
            {
                R[B] = FQ[0];
                ALU.setText(R[A]);
            }break;
            case 3:
            {
                R[B] = FQ[0];
                ALU.setText(FQ[0]);
            }break;
            case 4:
            {
                int x = Integer.parseInt(FQ[0],16);
                int y = Integer.parseInt(FQ[1],16);
                R[B] = Integer.toHexString(x/2);
                FQ[1] = Integer.toHexString(y/2);
                ALU.setText(FQ[0]);
            }break;
            case 5:
            {
                int x = Integer.parseInt(FQ[0],16);
                R[B] = Integer.toHexString(x/2);

                ALU.setText(FQ[0]);
            }break;
            case 6:
            {
                int x = Integer.parseInt(FQ[0],16);
                int y = Integer.parseInt(FQ[1],16);
                x=x*2;
                if (x>65535){
                    x=x-65536;
                }
                y=y*2;
                if (y>65535){
                    y=y-65536;
                }
                R[B] = Integer.toHexString(x);
                FQ[1] = Integer.toHexString(y);
                ALU.setText(FQ[0]);
            }break;
            case 7:
            {
                int x = Integer.parseInt(FQ[0],16);
                x=x*2;
                if (x>65535){
                    x=x-65536;
                }
                R[B] = Integer.toHexString(x);
                ALU.setText(FQ[0]);
            }break;
            default:
                break;
        }
        /*显示寄存器的当前值*/
        R0_d.setText(R[0]);
        R1_d.setText(R[1]);
        R2_d.setText(R[2]);
        R3_d.setText(R[3]);
        R4_d.setText(R[4]);
        R5_d.setText(R[5]);
        R6_d.setText(R[6]);
        R7_d.setText(R[7]);
        R8_d.setText(R[8]);
        R9_d.setText(R[9]);
        R10_d.setText(R[10]);
        R11_d.setText(R[11]);
		/*测试用
		System.out.println(inFunction1);
		System.out.println(inFunction2);
		System.out.println(s_R);
		System.out.println(s_S);
		System.out.println(ans);
		System.out.println(FQ[0]);
		System.out.println(I8_6+"i86");
		System.out.println(I5_3+"i53");
		System.out.println(I2_0+"i20");
		System.out.println(SST+"sst");
		for(int ii = 0;ii < 12;ii++)
			System.out.println(R[ii]);
		System.out.println(i);
		*/
    }

    private void jButton2ActionPerformed(ActionEvent evt) { //RESET键响应函数，将所有按键复原，将所有寄存器值清空
        for(int i = 0;i < 12;i++)
        {
            FunctionNum1[i] = '0';
            FunctionNum2[i] = '0';
        }
        for(int i = 0;i < 12;i++)
            R[i] = null;
        FQ[0] = FQ[1] = null;
        ALU.setText(" ");
        Data.setText("输入四位十六进制数");
        NumB1.setSelected(false);
        NumB2.setSelected(false);
        NumB3.setSelected(false);
        NumB4.setSelected(false);
        NumB5.setSelected(false);
        NumB6.setSelected(false);
        NumB7.setSelected(false);
        NumB8.setSelected(false);
        NumB9.setSelected(false);
        NumB10.setSelected(false);
        NumB11.setSelected(false);
        NumB12.setSelected(false);
        NumB13.setSelected(false);
        NumB14.setSelected(false);
        NumB15.setSelected(false);
        NumB16.setSelected(false);
        NumB17.setSelected(false);
        NumB18.setSelected(false);
        NumB19.setSelected(false);
        NumB20.setSelected(false);
        NumB21.setSelected(false);
        NumB22.setSelected(false);
        NumB23.setSelected(false);
        NumB24.setSelected(false);
        R0_d.setText(R[0]);
        R1_d.setText(R[1]);
        R2_d.setText(R[2]);
        R3_d.setText(R[3]);
        R4_d.setText(R[4]);
        R5_d.setText(R[5]);
        R6_d.setText(R[6]);
        R7_d.setText(R[7]);
        R8_d.setText(R[8]);
        R9_d.setText(R[9]);
        R10_d.setText(R[10]);
        R11_d.setText(R[11]);
    }

    /*获得源操作数的函数*/
    public String getR(String I,int a)
    {
        if(I.equalsIgnoreCase("000")||I.equalsIgnoreCase("001"))
            return R[a];
        else if(I.equalsIgnoreCase("010")||I.equalsIgnoreCase("011")||
                I.equalsIgnoreCase("100"))
            return "0000";
        else
            return Data.getText();
    }

    /*获得目的操作数的函数*/
    public String getS(String I,String[] fq,int a,int b)
    {
        if(I.equalsIgnoreCase("000")||I.equalsIgnoreCase("010")||
                I.equalsIgnoreCase("110"))
            return fq[1];
        else if(I.equalsIgnoreCase("001")||I.equalsIgnoreCase("011"))
            return R[b];
        else if(I.equalsIgnoreCase("100")||I.equalsIgnoreCase("101"))
            return R[a];
        else
            return "0000";
    }

    /*执行运算的函数*/
    public String Do(String I,String SST,String SSHSCI,String r,String s,char[] czvs)
    {
        //System.out.println(I+"iiiii");
        int iR = Integer.parseInt(r,16);
        int iS = Integer.parseInt(s,16);
        int ans = 0;
        if(SST.equals("001"))
        {
            if(I.equalsIgnoreCase("000"))
            {
                ans = iR + iS + Cin;
                if(ans > 65535)
                {
                    ans = ans - 65535;
                    czvs[2] = '1';
                }
                if(ans == 0)
                    czvs[1] = '1';
            }
            else if(I.equalsIgnoreCase("001") && SSHSCI.equals("001"))
            {
                ans = iS - iR;
                if(ans < 0)
                {
                    int l = Integer.toString(0 - ans).length();
                    czvs[3] = '1';
                    ans = (int) (Math.pow(10,l) + ans);
                }
            }
            else if(I.equalsIgnoreCase("010") && SSHSCI.equals("001"))
            {
                ans = iR - iS;
                if(ans < 0)
                {
                    int l = Integer.toString(0 - ans).length();
                    czvs[3] = '1';
                    ans = (int) (Math.pow(10,l) + ans);
                }
            }
            else if(I.equalsIgnoreCase("011"))
                ans = iR | iS;
            else if(I.equalsIgnoreCase("100"))
                ans = iR & iS;
            else if(I.equalsIgnoreCase("101"))
                ans = ~(iR & iS);
            else if(I.equalsIgnoreCase("110"))
                ans = iR ^ iS;
            else
                ans = ~(iR ^ iS);
            System.out.println(ans+"aaaa");
            return Integer.toHexString(ans);
        }
        else
        {
            System.out.println(ans);
            return "error";
        }
    }
    private void DataMouseClicked(MouseEvent evt) {
        Data.setText("");
    }

    private void ALUMouseClicked(MouseEvent evt) {
        if(ALU.getText().equals("error"))
        {
            JOptionPane.showMessageDialog(null, "SST应设置为001",
                    "错误提示",JOptionPane.ERROR_MESSAGE);
        }
    }
}
